package com.qqserver.service;

/**
 * 管理线程
 */

import java.util.HashMap;
import java.util.Iterator;

public class ManageServerConnectClientThread {
    //存放线程的HashMap集合，key是用户id,value是线程
    private static HashMap<String,ServerConnectClientThread> hm = new HashMap<>();

    //返回HashMap
    public static HashMap<String, ServerConnectClientThread> getHm() {
        return hm;
    }

    //添加线程
    public static void addServerConnectClientThread(String userId, ServerConnectClientThread serverConnectClientThread){
        hm.put(userId,serverConnectClientThread);
    }
    //取出线程
    public static ServerConnectClientThread getServerConnectClientThread(String userId){
        return hm.get(userId);
    }

    //移除线程
    public static void removeServerConnectClientThread(String userId){
        hm.remove(userId);
    }
    //获取集合中的key，也就是开通通信的id,在线用户
    public static String getOnlineUser() {
        //迭代器遍历集合，取出Key值,keyset()获取所有的键
        Iterator<String> iterator = hm.keySet().iterator();
        String onlineUserList = "";
        while (iterator.hasNext()){
            onlineUserList += iterator.next().toString()+" ";
        }
        return onlineUserList;
    }
}
